<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS中的switch和while和for</title>
</head>
<body>

<script>
    // switch: 判断是星期几
    let weekday = 8;
    switch (weekday) {
        case 1:
            document.write("星期一" + "<br/>");
            break;
        case 2:
            document.write("星期二" + "<br/>");
            break;
        case 3:
            document.write("星期三" + "<br/>");
            break;
        case 4:
            document.write("星期四" + "<br/>");
            break;
        case 5:
            document.write("星期五" + "<br/>");
            break;
        case 6:
            document.write("星期六" + "<br/>");
            break;
        case 7:
            document.write("星期日" + "<br/>");
            break;
        default:
            document.write("骚年,星期有问题" + "<br/>");
            break;
    }

    // while: 求1-100的和
    let sum = 0; // 求和变量,保存总和
    let i = 1; // i在循环中会变化 i=1,2,3...100;
    while (i <= 100) {
        sum += i;
        i++;
    }
    document.write(sum + "<br/>");


    // 创建数组
    let arr = new Array(11, 22, 33, 44);

    // 普通for循环
    for (let i = 0; i < arr.length; i++) { // i表示数组的索引
        // 取出数组的元素
        document.write(arr[i] + "<br/>");
    }

    document.write("-----------------------" + "<br/>");

    // 增强for循环: for...of
    for (let num of arr) {
        document.write(num + "<br/>");
    }
</script>

</body>
</html>